//
//  BudgetHomeVC.m
//  BaseProject
//
//  Created by mac on 2020/10/26.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "BudgetHomeVC.h"
#import "BudgetPieVC.h"
@interface BudgetHomeVC ()<UITextFieldDelegate>
@property(nonatomic,strong)UIScrollView *mainView;
@property(nonatomic,strong)UIImageView *topIV;
@property(nonatomic,strong)UIView *bgView;
@property(nonatomic,strong)UILabel *titleLab;
@property(nonatomic,strong)UITextField *moneyTF;
@property(nonatomic,strong)UIView *lineView;
@property(nonatomic,strong)UIButton *beginButton;
@property(nonatomic,strong)UILabel *tipLab;
@property(nonatomic,strong)UIImageView *logoIV;
@end

@implementation BudgetHomeVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createProperty];
    [self createUI];
}
- (void)createProperty
{
    self.view.backgroundColor = [UIColor whiteColor];
}
- (void)createUI
{
    self.title = @"婚礼预算表";
    [self mainView];
    [self topIV];
    [self bgView];
    self.titleLab.text = @"为您分配最合理的婚礼预算";
    [self moneyTF];
    [self lineView];
    [self beginButton];
    self.tipLab.text = @"*全国80%的新人婚礼预算在5-50万之间";
    [self logoIV];
    self.mainView.contentSize = CGSizeMake(0, MAX(self.mainView.height + 1, self.logoIV.bottom + kBottomSafeHeight) + 20*ADAPTER_WIDTH);
}
#pragma mark - TF
- (void)addObserverPhoneTF:(UITextField *)tf
{
    
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    NSInteger content = textField.text.integerValue;
    textField.text = [NSString stringWithFormat:@"%ld",content];
}
#pragma mark - click
- (void)clickBeginButtoon:sender
{
    if (self.moneyTF.text.integerValue < 20000) {
        [Utilities showToast:@"哎呀！预算给得有点少"];
        return;
    }
    !self.callBackTotalMoney ?: self.callBackTotalMoney (self.moneyTF.text.integerValue);
    [[TTUserModel sharedObject].userModelDefault setValue:[NSNumber numberWithInteger:self.moneyTF.text.integerValue] forKey:@"buget_totalMoney"];
    if (self.native) {
        BudgetPieVC *vc = [[BudgetPieVC alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    } else {
        [self.navigationController popViewControllerAnimated:YES];
    }
}
#pragma mark - lazy懒加载
- (UIScrollView *)mainView
{
    if (!_mainView) {
        UIScrollView *view = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, TTScreenWidth, TTScreenHeight - kNavBarAndStatusBarHeight)];
        [self.view addSubview:view];
        view.backgroundColor = RGB(255, 219, 219);
        _mainView = view;
    }
    return _mainView;
}
- (UIImageView *)topIV
{
    if (!_topIV) {
        UIImageView *iv = [[UIImageView alloc]init];
        [self.mainView addSubview:iv];
        iv.contentMode = UIViewContentModeScaleAspectFill;
        iv.clipsToBounds = YES;
        iv.frame = CGRectMake((TTScreenWidth - 308*ADAPTER_WIDTH) * 0.5, 36*ADAPTER_WIDTH, 308*ADAPTER_WIDTH, 196*ADAPTER_WIDTH);
        NSString *imagePath = [[NSBundle mainBundle]pathForResource:@"BudgetHome_top" ofType:@"png"];
        UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
        iv.image = image;
        _topIV = iv;
    }
    return _topIV;
}
- (UIView *)bgView
{
    if (!_bgView) {
        UIView *view = [[UIView alloc]init];
        view.backgroundColor = [UIColor whiteColor];
        view.frame = CGRectMake(20*ADAPTER_WIDTH, 232*ADAPTER_WIDTH, TTScreenWidth - 40*ADAPTER_WIDTH, 262*ADAPTER_WIDTH);
        [self.mainView addSubview:view];
        view.layer.cornerRadius = 5*ADAPTER_WIDTH;
        view.layer.shadowColor = RGB(240, 240, 240).CGColor;
        view.layer.shadowOffset = CGSizeMake(0, 0);
        view.layer.shadowRadius = 5;
        view.layer.shadowOpacity = 1;
        _bgView = view;
    }
    return _bgView;
}
- (UILabel *)titleLab
{
    if (!_titleLab) {
        UILabel *lab = [[UILabel alloc]init];
        [self.bgView addSubview:lab];
        lab.font = [UIFont systemFontOfSize:15*ADAPTER_WIDTH weight:UIFontWeightBold];
        lab.textColor = RGB(51, 51, 51);
        lab.textAlignment = NSTextAlignmentLeft;
        lab.numberOfLines = 1;
        lab.frame = CGRectMake(17*ADAPTER_WIDTH, 24*ADAPTER_WIDTH, self.bgView.width - 34*ADAPTER_WIDTH, 16*ADAPTER_WIDTH);
        _titleLab = lab;
    }
    return _titleLab;
}
- (UITextField *)moneyTF
{
    if (!_moneyTF) {
        UITextField *tf = [[UITextField alloc]initWithFrame:CGRectMake(10*ADAPTER_WIDTH, 83*ADAPTER_WIDTH, self.bgView.width - 20*ADAPTER_WIDTH, 35*ADAPTER_WIDTH)];
        [self.bgView addSubview:tf];
        tf.textColor = RGB(51, 51, 51);
        tf.font = [UIFont systemFontOfSize:15*ADAPTER_WIDTH weight:UIFontWeightRegular];
        tf.clearButtonMode = UITextFieldViewModeWhileEditing;
        tf.keyboardType = UIKeyboardTypeNumberPad;//UIKeyboardTypeNumberPad UIKeyboardTypePhonePad电话板面 UIKeyboardTypeDecimalPad 小数点
        tf.tintColor = [UIColor orangeColor];
        tf.textAlignment = NSTextAlignmentCenter;
        [tf addTarget:self action:@selector(addObserverPhoneTF:) forControlEvents:UIControlEventEditingChanged];
        tf.secureTextEntry = NO;
        NSMutableAttributedString *placeHolder = [[NSMutableAttributedString alloc]initWithString:@"请输入您的预算金额20000起"];
        placeHolder.color = RGBA(218, 218, 218, 1);
        placeHolder.font = [UIFont systemFontOfSize:15*ADAPTER_WIDTH weight:UIFontWeightRegular];
        tf.attributedPlaceholder = placeHolder;
        tf.delegate = self;
        _moneyTF = tf;
    }
    return _moneyTF;
}
- (UIView *)lineView
{
    if (!_lineView) {
        UIView *view = [[UIView alloc]init];
        view.backgroundColor = RGB(218, 218, 218);
        view.frame = CGRectMake(16*ADAPTER_WIDTH, 128*ADAPTER_WIDTH, self.bgView.width - 32*ADAPTER_WIDTH, 0.5);
        [self.bgView addSubview:view];
        _lineView = view;
    }
    return _lineView;
}
- (UIButton *)beginButton
{
    if (!_beginButton) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.bgView addSubview:button];
        [button setTitle:@"开始计算" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:18*ADAPTER_WIDTH weight:UIFontWeightBold];
        [button addTarget:self action:@selector(clickBeginButtoon:) forControlEvents:UIControlEventTouchUpInside];
        button.frame = CGRectMake(40*ADAPTER_WIDTH, 171*ADAPTER_WIDTH, 254*ADAPTER_WIDTH, 40*ADAPTER_WIDTH);
        
        CAGradientLayer *gradientLayer = [[CAGradientLayer alloc]init];
        gradientLayer.startPoint = CGPointMake(0, 0);
        gradientLayer.endPoint = CGPointMake(1, 0);
        gradientLayer.frame = CGRectMake(0, 0, CGRectGetWidth(button.frame), CGRectGetHeight(button.frame));
        UIColor *startColor = RGBA(250, 66, 75, 1);
        UIColor *endColor = RGBA(250, 107, 90, 1);
        gradientLayer.colors = @[(__bridge id)startColor.CGColor,(__bridge id)endColor.CGColor];
        [button.layer addSublayer:gradientLayer];
        
        gradientLayer.cornerRadius = 20*ADAPTER_WIDTH;
        gradientLayer.masksToBounds = YES;
        
        UILabel *lab = [[UILabel alloc]init];
        [button addSubview:lab];
        lab.text = @"开始计算";
        lab.frame = CGRectMake(0, 0, button.width, button.height);
        lab.textColor = [UIColor whiteColor];
        lab.font = [UIFont systemFontOfSize:18*ADAPTER_WIDTH weight:UIFontWeightBold];
        lab.textAlignment = NSTextAlignmentCenter;
        
        _beginButton = button;
    }
    return _beginButton;
}
- (UILabel *)tipLab
{
    if (!_tipLab) {
        UILabel *lab = [[UILabel alloc]init];
        [self.bgView addSubview:lab];
        lab.font = [UIFont systemFontOfSize:12*ADAPTER_WIDTH weight:UIFontWeightRegular];
        lab.textColor = RGB(153, 153, 153);
        lab.textAlignment = NSTextAlignmentCenter;
        lab.numberOfLines = 1;
        lab.frame = CGRectMake(0, self.beginButton.bottom + 17*ADAPTER_WIDTH, self.bgView.width, 13*ADAPTER_WIDTH);
        _tipLab = lab;
    }
    return _tipLab;
}
- (UIImageView *)logoIV
{
    if (!_logoIV) {
        UIImageView *iv = [[UIImageView alloc]init];
        [self.mainView addSubview:iv];
        
        NSString *imagePath = [[NSBundle mainBundle]pathForResource:@"BudgetHome_logo" ofType:@"png"];
        UIImage *image = [UIImage imageWithContentsOfFile:imagePath];        
        iv.image = image;
        iv.clipsToBounds = YES;
        iv.frame = CGRectMake((TTScreenWidth - 61*ADAPTER_WIDTH) * 0.5, self.bgView.bottom + 22*ADAPTER_WIDTH, 61*ADAPTER_WIDTH, 64*ADAPTER_WIDTH);
        _logoIV = iv;
    }
    return _logoIV;
}
@end
